2019年鐵人賽 、 JS 、 YouDon'tKnowJSabout:blank
純空白分頁
console.log(..)
print在控制台上
alert(..)
跳出提示框並print在上面
prompt(..)var age = prompt('what is your age?')
console.log('age is' + ' ' + age)
alert('age is' + ' ' + age)


=
+ , - , * , /
+= , -= , *= , /=
var a += 2 
//等同下面
var a = a + 2
遞增與遞減(Increment/Decrement)
++ , --
a1++是先給值再計算,++a2是先計算再給值
以C++來看a++和++a的運作,回傳值不ㄧ樣
相等性(Equality):
==跟===都是比較值的相等性,差別在於前者允許值可以強制轉型,後者不允許
| 寬鬆(loose) | 嚴格(strict) | |
|---|---|---|
| 相等 | == | 
=== | 
| 不相等 | != | 
!== | 
更多比較:JS-Equality-Table
< , > , <= , >=
NaN這個無效數字值var a = 11;
var b = "12";
var c = "13";
a < b;		// true
b < c;		// true
var x = 2;
var y = "hi";
x < y;		// false,y被強制轉型成NaN
x > y;		// false,y被強制轉型成NaN
x == y;		// false,y被強制轉型成NaN
比較(Comparison)< , > , <= , >=
邏輯(Logical)&& , ||
typeof運算子(operator)檢查值的typevar a;
typeof a;			// "undefined"
a = "hi";
typeof a;			// "string"
a = 42;
typeof a;			// "number"
a = true;
typeof a;			// "boolean"
a = null;
typeof a;			// "object",這是JS中奇怪的bug
a = { b: "c" };
typeof a;			// "object"
型別之間做轉換需要強制轉型(coercion),強制轉型有兩種:
以下值被強制轉換成boolean值時,視為false :
''(空字串)
{}包含;
var
若不宣告會自動提升變成全域
在function內宣告就是區域變數,scope只在function內

let:
if(..){..}
var JasonKg = 101
if(JasonKg > 100){
    console.log('Jason is 操')
}
switch(..){..}
var HenryKg = 90
switch (HenryKg) {
    case 90:
    case 95:
      console.log('我知道要+5')
      break;
    case 96:
      console.log('你比Jason瘦但ㄧ樣操')
      break;
    default:
      console.log('恭喜你跟Jasonㄧ樣是操胖')
  }
{}裡的程式每次執行時,就稱做一次迭代(iteration)break停止迴圈for(..){}for (var i = 0; i <= 9; i = i + 1) {
	console.log( i );
}
// 0 1 2 3 4 5 6 7 8 9
while(..){..}
條件一旦判斷為false,就不進{}裡執行
do{..}while(..);
條件就算判斷為false,還是會進{}裡執行一次
var obj = {
	a: "hello world",
	b: 42,
	c: true
};
//透過.訪問屬性
obj.a;		// "hello world"
obj.b;		// 42
obj.c;		// true
//透過[]訪問屬性
obj["a"];	// "hello world"
obj["b"];	// 42
obj["c"];	// true

var arr = [
	"hello world",
	42,
	true
];
arr[0];			// "hello world"
arr[1];			// 42
arr[2];			// true
arr.length;		// 3
typeof arr;		// "object"
